//
//  ForgetPwdView.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/4/1.
//

import SwiftUI
import FlowStacks

struct ForgetPwdView: View {
    @EnvironmentObject var navigator: FlowNavigator<LoginStack>
    @StateObject private var viewModel = ForgetPwdViewModel()
    var body: some View {
        VStack(spacing: 0) {
            NavigationBar(title: "", leading: AnyView(
                Button(action: {
                    navigator.pop()
                }) {
                    Image(systemName: "chevron.left")
                        .foregroundColor(.black)
                }
            ))

            Text("forget password")
                .font(.system(size: 34, weight: .bold))
                .padding(.top, 50)
                .padding(.leading, 20)
                .frame(maxWidth: .infinity, alignment: .leading)
            CustomTextField(text: $viewModel.account, placeholder: "email or phoneNum", isValid: viewModel.isAccountValid)
                .padding(.horizontal, 20)
                .padding(.top, 20)

            Spacer()
            Button(action: {
                viewModel.requestVerifyCode()
            }) {
                Text("next step")
                    .font(.system(size: 14))
                    .foregroundColor(.white)
            }
            .frame(maxWidth: .infinity)
            .frame(height: 44)
            .background(!viewModel.isAccountValid ? AppColors.Brand6.opacity(0.5) : AppColors.Brand6)
            .cornerRadius(22)
            .padding(.horizontal, 30)
            .padding(.bottom, 40)
            .foregroundColor(.white)
            .disabled(!viewModel.isAccountValid)

        }
        .onChange(of: viewModel.sendSuccess) { result in
            navigator.push(.verificationCode(account: viewModel.account, type: .notRegister, verifyType: .modifyPwd))
        }.toast(isPresented:$viewModel.showToast , message: viewModel.toastMsg)
    }
}
